package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectPageParamDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;


@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    //分页查询
    @GetMapping
    @ApiOperation(value = "分页查询项目信息")
    public ResponseResult<PageResponse<NursingProjectVo>> selectByPage(NursingProjectPageParamDto nursingPeojectPageParamDto){
        PageResponse<NursingProjectVo> response = nursingProjectService.selectByPage(nursingPeojectPageParamDto);
        return success(response);
    }

    //新增项目
    @PostMapping
    @ApiOperation(value = "新增项目")
    public ResponseResult insert(@RequestBody NursingProjectDto nursingProjectDto){
        log.info("新增项目：{}", nursingProjectDto);
        nursingProjectService.addProject(nursingProjectDto);
        return success();
    }

    //根据ID查询项目
    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询项目")
    public ResponseResult<NursingProjectVo> selectById(@ApiParam(value = "项目ID",required = true)
                                                           @PathVariable Integer id){
        log.info("要编辑的项目ID：{}",id);
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }
    //编辑项目
    @PutMapping
    @ApiOperation(value = "更新项目信息")
    public ResponseResult updateProject(@RequestBody NursingProjectDto nursingProjectDto){
        log.info("更新项目信息：{}",nursingProjectDto);
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }

    //启用/禁用项目
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用/禁用项目")
    public ResponseResult updateStatus(@ApiParam(value = "项目ID") @PathVariable Long id,
                                       @ApiParam(value = "项目状态")@PathVariable Integer status){
        log.info("将项目{}的状态修改为{}",id,status);
        nursingProjectService.updateStatus(id,status);
        return success();
    }

    //删除项目
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除项目")
    public ResponseResult delectProject (@ApiParam(value = "项目ID",required = true) @PathVariable Long id){
        log.info("删除项目：{}",id);
        nursingProjectService.deleteProjectById(id);
        return success();
    }

    //查询所有项目
    @GetMapping("/all")
    @ApiOperation(value = "查询所有项目")
    public ResponseResult<List<NursingProjectVo>> selectAll(){
        log.info("查询所有项目：");
        List<NursingProjectVo> nursingProjectVo = nursingProjectService.getAll();
        return success(nursingProjectVo);
    }







}
